﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using GalaSoft.MvvmLight.Command;

namespace WpfApplication1
{
    public class MyVm : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string name)
        {
            var handler = PropertyChanged;
            if (handler == null) return;

            var e = new PropertyChangedEventArgs(name);
            handler(this, e);
        }

        private string _myVideoPath;
        public string MyVideoPath
        {
            get { return _myVideoPath; }
            set
            {
                _myVideoPath = value;
                RaisePropertyChanged("MyVideoPath");
            }
        }

        private PlayerStatus _videoStatus;
        public PlayerStatus VideoStatus
        {
            get { return _videoStatus; }
            set
            {
                _videoStatus = value;
                RaisePropertyChanged("VideoStatus");
            }
        }

        public RelayCommand SetStatusCommand {get; private set;}

        public MyVm()
        {
            VideoStatus = PlayerStatus.Stop;
            MyVideoPath = @"C:\Users\Public\Videos\Sample Videos\Wildlife.wmv";
            SetStatusCommand = new RelayCommand(SetStatus);
        }

        private void SetStatus()
        {
            switch (VideoStatus)
            {
                case PlayerStatus.Play:
                    VideoStatus = PlayerStatus.Pause;
                    break;
                case PlayerStatus.Pause:
                    VideoStatus = PlayerStatus.Play;
                    break;
                case PlayerStatus.Stop:
                    VideoStatus = PlayerStatus.Play;
                    break;
            }
        }

        //private void storyboard_CurrentTimeInvalidated(object sender, EventArgs e)
        //{
        //    storyboardClock = (Clock)sender;
        //    this.sliderPosition.ValueChanged -= new RoutedPropertyChangedEventHandler<double>(sliderPosition_ValueChanged);
        //    if (IsMediaOpened && storyboardClock.CurrentTime != null)
        //    {
        //        sliderPosition.Value = storyboardClock.CurrentTime.Value.TotalSeconds;
        //    }
        //    this.sliderPosition.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderPosition_ValueChanged);
        //}

        //private void media_MediaOpened(object sender, RoutedEventArgs e)
        //{
        //    this.sliderPosition.Maximum = this.media.NaturalDuration.TimeSpan.TotalSeconds;
        //    this.IsMediaOpened = true;
        //}

        //private void sliderPosition_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        //{
        //    storyboardClock.Controller.Seek(new TimeSpan(0, 0, 0, Convert.ToInt32(this.sliderPosition.Value)), TimeSeekOrigin.BeginTime);
        //}
    }
}
